package mest.controller.cxj;


import com.alibaba.fastjson.JSON;
import mest.VO.cxj.ProductJobVO;
import mest.VO.cxj.ProductOrderVO;
import mest.entity.product_job;
import mest.service.cxj.ProductJobService;
import mest.service.system.DBService;
import mest.util.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productJob")
@CrossOrigin
public class ProductJobController {

    @Autowired
    private ProductJobService productJobService;

    @Autowired
    private DBService dbService;

    /**
     * 根据生产单Id查询生产作业单信息
     *
     * @return
     */
    @GetMapping("selectById")
    public String selectById(@RequestParam Integer page, @RequestParam Integer limit,
                            @RequestParam(required = false) Integer poId) {
        ResultObj resultObj = null;
        String theirDb=dbService.getCompanyDB();
        try {
            List<ProductJobVO> productjobList = productJobService.selectAllproductJobByPoId(page, limit, poId,theirDb);
            Integer count = productJobService.selectCountproductJobByPoId(poId,theirDb);
            resultObj = new ResultObj(0, "success", count, productjobList);
        } catch (Exception e) {
            e.printStackTrace();
            resultObj = ResultObj.builder().code(-2).msg("系统异常,请联系管理员").build();
        }
        return JSON.toJSONString(resultObj);
    }

}
